package com.snails.oj;

import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
 * DrawingMachine
 * <a href="https://zhuanlan.zhihu.com/p/645558582">计算面积</a>
 *
 * @since 2024-06-22
 */
public class DrawingMachine {

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in, StandardCharsets.UTF_8);
        int row = cin.nextInt();
        int stopPoint = cin.nextInt();
        int[][] operations = new int[row][2];
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < 2; j++) {
                operations[i][j] = cin.nextInt();
            }
        }
        cin.close();
        long result = getMinArea(stopPoint, operations);
        System.out.println(result);
    }

    private static long getMinArea(int stopPoint, int[][] operations) {
        // 定义原始坐标点及面积
        int lastX = 0;
        int lastY = 0;
        int area = 0;
        for (int[] operation : operations) {
            // 拿到当前x坐标及y轴偏移量
            int x = operation[0];
            int offsetY = operation[1];
            // 计算当前面积并进行累加, 当前节点面积计算 = (当前x轴值-上一个x轴值) * (上一个节点Y轴绝对值)
            area += (x - lastX) * Math.abs(lastY);
            // 计算完面积需要对当前坐标进行赋值处理
            lastX = x;
            lastY += offsetY;
        }
        // 还需判断如果x轴最后一个节点值小于目标x轴值，则还需单独加上这部分
        if (lastX < stopPoint) {
            area += (stopPoint - lastX) * Math.abs(lastY);
        }
        return area;
    }
}
